/// 某个医院的租借记录汇总列表

var app = getApp()
//常量数据配置
var ConstantData = require('../../../../common/constant_data.js')
//获取应用实例  
Page({

  data: {
    leaseData: '',
    hospitalName: '通医附',

  },

      

  onLoad: function (options) {
    var that = this;

    var mecId = options.mecId;
    var hospitalName = options.hospitalName;
    var startDate = options.startDate;
    var endDate = options.endDate;
    var position = options.position;
    var eqtCount = options.eqtCount;
    var isReal = options.isReal;
    that.data.isReal = isReal;
    this.setData({
      mecId: mecId,
      hospitalName: hospitalName,
      startDate:startDate,
      endDate:endDate,
      position:position,
      eqtCount: eqtCount
    });

    that.init(startDate,endDate,position);
  },

  /** 
   * 点击
   */
  toDetail: function (e) {
    var date = e.currentTarget.dataset.date;
    var that = this;
    console.log(e);
    wx.navigateTo({
      url: '../leasedetail/leasedetail?mecId=' + that.data.mecId + "&hospitalName=" + that.data.hospitalName + "&date=" + date 
      + "&position=" + that.data.position + "&isReal=" + that.data.isReal,
    });

  },

  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function () {
    // var that = this;
    // if (that.data.loading && !that.data.loadingComplete) {
    //   that.setData({
    //     pageNum: that.data.pageNum + 1,  //每次触发上拉事件，把searchPageNum+1  
    //   });
    //   that.getApageLeaseRecord();
    // }
  },


  init: function (startDate,endDate,position) {

    var that = this;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_statistic/lease/position',
        header: header,
        data: {
          startDate: startDate,
          endDate: endDate,
          mecId: that.data.mecId,
          position:position,
          isReal:that.data.isReal
        },
        success: function (res) {
          console.log("aaaa---->", res);
          var list = Array();
          for(var i=0;i<res.data.length;i++) {
            var totalCount = parseInt(res.data[i].counts);
            var avgCount = that.data.eqtCount == 0 ? 0 : totalCount / that.data.eqtCount;
            res.data[i].avg_count = avgCount.toFixed(2);
            list.push(res.data[i]);
          }
          that.setData({
            leaseData: list
          })
        }
      })
    });  


   
  }
})



